import { create } from "zustand";
import UserApi from "../api/userApi.js";
import { setToken, clearToken } from "../utils/token.js";
const useLoginStore = create((set) => ({
  token: "",
  userLogin: async (userForm) => {
    // const { data } = await UserApi.login(userForm);

    const data = {
      userInfo: {
        name: "qwqww",
      },
      token: "34u5oi34oi345o34",
      message: "1231",
      code: 200,
    };
    if (data.code == 200) {
      localStorage.setItem("user", JSON.stringify(data.userInfo));
      setToken(data.token);
    } else {
      throw new Error(data.message);
    }
  },
  // 退出登录
  userLogout: () => {
    clearToken();
    // 清除用户信息
    localStorage.removeItem("user");
  },
}));
export default useLoginStore;
